import java.util.Scanner;

public class Test1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine() ;
        int sum = 0 ;
        for(int i = 0 ; i < str.length() ; i ++){
            for(int j = i +2 ; j <= str.length() ; j++){
                String ret = str.substring(i , j);
                int tmp = isHuiWen(ret) ;
                if(sum == 0 && tmp != -1){
                    sum = tmp ;
                }else if(tmp != -1 && tmp < sum){
                    sum = tmp ;
                }
            }
        }
        if(sum == 0 ){
            System.out.println(-1);
        }else{
            System.out.println(sum);
        }


    }
    private static int isHuiWen(String str){
        if(str == null || str.length() <= 1)return -1 ;
        int start = 0 ;
        int end = str.length() - 1 ;
        while(start <= end){
            if(str.charAt(start) != str.charAt(end)){
                return -1 ;
            }
            start++ ;
            end -- ;
        }
        return str.length() ;
    }
}
